<template>
  <div class="base-element-document"
    :style="{
      top: elementInfo.top + 'px',
      left: elementInfo.left + 'px',
      width: elementInfo.width + 'px',
      height: elementInfo.height + 'px',
    }"
  >
    <div
      class="rotate-wrapper"
      :style="{ transform: `rotate(${elementInfo.rotate}deg)` }"
    >
      <div class="element-content">
        <iframe
          title="doc iframe"
          ref="iframe"
          :id="elementInfo.id"
          :src="elementInfo.url"
          :width="elementInfo.width"
          :height="elementInfo.height"
          :frameborder="0" 
          :allowfullscreen="true"
        ></iframe>

        <!-- <div class="mask"></div> -->
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { type PPTDocumentElement } from '@/types/slides'
import type { PropType} from 'vue'
// eslint-disable-next-line no-duplicate-imports
import { onMounted, ref } from 'vue'

const props = defineProps({
  elementInfo: {
    type: Object as PropType<PPTDocumentElement>,
    required: true,
  },
})

const iframe = ref(null)

// 设置滚动效果
onMounted(() => {
  // @ts-ignore
  iframe.value.addEventListener('load', () => {
    setTimeout(() => {
      // @ts-ignore
      const iframeDocument = iframe.value.contentDocument || iframe.value.contentWindow.document
      iframeDocument.documentElement.scrollTop = props.elementInfo.scrollTop
    }, 500)
  })
})
</script>

<style lang="scss" scoped>
.base-element-document {
  position: absolute;
}
.element-content {
  width: 100%;
  height: 100%;
}
.mask {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}
</style>